package com.jsoft.dao.impl;

import com.jsoft.dao.ContractDao;
import com.jsoft.entiy.Contract;
import com.jsoft.entiy.vo.ContractVo;
import com.jsoft.util.DAOImpl;

import java.util.List;

/**
 * @program: CPM
 * @description:
 * @author: beibei
 * @create: 2022-09-07 17:03
 */
public class ContractDaoImpl extends DAOImpl<Contract> implements ContractDao {

    //查询所有合同信息
    @Override
    public List<Contract> getAll() {
        String sql = "select * from contract";
        List<Contract> contracts  = null;
        try {
            contracts = getForList(sql);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return contracts;
    }

    //添加合同信息
    @Override
    public Integer save(Contract contract) {

        String sql = "INSERT INTO contract VALUE (?,?,?,?,?,?,?,?,?,?,?,?,?);";
        Integer update = null;
        try {
            update = update(sql, contract.getId(), contract.getEId(), contract.getType(), contract.getStartDate(), contract.getEndDate(), contract.getMoney(), contract.getPayway(), contract.getBuyId(), contract.getSellId(), contract.getPayDate(), contract.getPaystate(), contract.getGmtCreate(), contract.getGmtModified());
        } catch (Exception e) {
            e.printStackTrace();
        }

        return update;
    }

    @Override
    public Integer deleteById(Integer id) {
        String sql = "delete from contract where id = ?;";
        Integer update = null;
        try {
            update = update(sql, id);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return update;
    }

    @Override
    public Integer updateContractById(Integer id, String payState) {
        String sql = "update contract set paystate = ? where id = ?";
        Integer update = null;
        try {
            update = update(sql, payState,id);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return update;
    }


}